package com.hluobo.gnnulibrary.broadcast;

import java.io.File;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;

public class DownloadCompleteReceiver extends BroadcastReceiver {

	private static final String TAG = "com.hluobo.gnnulibrary";
	private static final String MY_PREFERENCES = "preferences";

	@Override
	public void onReceive(Context context, Intent intent) {
		
		Log.i(TAG, "下载完成----------------->");
		
		// 安转新版Application
		SharedPreferences preferences = context.getSharedPreferences(
				MY_PREFERENCES, Context.MODE_PRIVATE);
		String uriStr = preferences.getString("appURI", null);
		if (null != uriStr) {
			Intent intent2 = new Intent(Intent.ACTION_VIEW);
			intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			File file = new File(uriStr);
			intent2.setDataAndType(Uri.fromFile(file),
					"application/vnd.android.package-archive");
			context.startActivity(intent2);
		}
	}

}
